use std::fmt::{Display, Formatter};

use crate::json::lexer::Token;

#[derive(Debug)]
pub struct LexerError
{
    token: Token,
}

impl LexerError {
    pub fn new(token: Token) -> LexerError {
        LexerError { token }
    }
}

impl Display for LexerError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "Lexer Error, unknown token : {}", self.token.get_str())
    }
}

impl std::error::Error for LexerError {}

#[derive(Debug)]
pub struct ParserError {
    token: Token,
}


impl ParserError {
    pub fn new(token: Token) -> ParserError {
        ParserError { token }
    }
}

impl Display for ParserError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "Parser Error, illegal token : {}", self.token.get_str())
    }
}

impl std::error::Error for ParserError {}